﻿using Coldairarrow.Business.AM;
using Coldairarrow.Entity.AM;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.AM
{
    [Route("/AM/[controller]/[action]")]
    public class am_assetController : BaseApiController
    {
        #region DI

        public am_assetController(Iam_assetBusiness am_assetBus)
        {
            _am_assetBus = am_assetBus;
        }

        Iam_assetBusiness _am_assetBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<AM_Asset>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _am_assetBus.GetDataListAsync(input);
        }
        /// <summary>
        /// 通过资产二维码获取资产信息
        /// </summary>
        /// <param name="QrCode"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Am_assetDto> GetQrCodeAsset(string QrCode) {
            var data = await _am_assetBus.GetQrCodeAsset(QrCode);
            return data;
        }
        [HttpPost]
        public async Task<AM_Asset> GetTheData(IdInputDTO input)
        {
            return await _am_assetBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(AM_Asset data)
        {
            if (data.ID.IsNullOrEmpty())
            {
                InitEntity(data);

                await _am_assetBus.AddDataAsync(data);
            }
            else
            {
                await _am_assetBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _am_assetBus.DeleteDataAsync(ids);
        }

       
        #endregion
    }
}